import type { DragDropManager, XYCoord } from '../../classes/interface';
import type { DragSourceMonitor } from '../dragInterface';

class DragSourceMonitorImpl implements DragSourceMonitor {
  private handlerId: string = '';
  private manager: DragDropManager;
  public constructor(manager: DragDropManager) {
    this.manager = manager;
  }

  public receiveHandlerId(newHandlerId: string) {
    if (this.handlerId === newHandlerId) {
      return;
    }

    this.handlerId = newHandlerId;
  }

  public getHandlerId() {
    return this.handlerId;
  }

  public subscribeStateChange: (listenerFn: () => void) => void = (
    listenerFn,
  ) => {
    this.manager.subscribeStateChange(listenerFn);
  };

  public isDragging(): boolean {
    return this.manager.isDraggingSource(this.handlerId);
  }

  public getItem(): any {
    return this.manager.getDragItem();
  }

  public getDragStartNodeClientOffset(): XYCoord | undefined {
    return this.manager.getDragStartNodeClientOffset();
  }

  public getDragStartEventClientOffset(): XYCoord | undefined {
    return this.manager.getDragStartEventClientOffset();
  }

  public getDropResult(): any {
    return this.manager.getDropResult();
  }
}

export default DragSourceMonitorImpl;
